<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>Linux 命令- chgrp | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>Linux 命令- chgrp</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux命令/">Linux命令</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 Linux 系统里，文件或目录的权限的掌控以拥有者及所属群组来管理。可以使用 chgrp 指令变更文件与目录所属群组，这种方式采用群组名称或群组织识别码都可以。chgrp 命令就是 change group 的缩写！要被改变的组名必须要在 /etc/group 文件被存在才行。</p>
<h2 id="1-命令格式"><a href="#1-命令格式" class="headerlink" title="1.命令格式"></a>1.命令格式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chgrp [选项] [组] [文件]</div></pre></td></tr></table></figure>
<h2 id="2-命令功能"><a href="#2-命令功能" class="headerlink" title="2.命令功能"></a>2.命令功能</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;chgrp 命令可采用群组名称或群组织识别码的方式改变文件或目录的所属群组。使用权限是超级用户。</p>
<h2 id="3-命令参数"><a href="#3-命令参数" class="headerlink" title="3.命令参数"></a>3.命令参数</h2><h3 id="必要参数"><a href="#必要参数" class="headerlink" title="必要参数"></a>必要参数</h3><ul>
<li>-c 当发生改变时输出调试信息</li>
<li>-f 不显示错误信息</li>
<li>-R 处理指定目录以及其子目录下的所有文件</li>
<li>-v 运行时显示详细的处理信息</li>
<li>–dereference 作用于符号链接的指向，而不是符号链接本身</li>
<li>–no-dereference 作用于符号链接本身</li>
</ul>
<h3 id="选择参数"><a href="#选择参数" class="headerlink" title="选择参数"></a>选择参数</h3><ul>
<li>–reference=&lt;文件或者目录&gt;</li>
<li>–help 显示帮助信息</li>
<li>–version 显示版本信息</li>
</ul>
<h2 id="使用实例"><a href="#使用实例" class="headerlink" title="使用实例"></a>使用实例</h2><h3 id="实例1：改变文件的群组属性"><a href="#实例1：改变文件的群组属性" class="headerlink" title="实例1：改变文件的群组属性"></a>实例1：改变文件的群组属性</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chgrp -v bin log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">---xrw-r-- 1 root root 302108 11-13 06:03 log2012.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># chgrp -v bin log2012.log</span></div><div class="line">“log2012.log” 的所属组已更改为 bin</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">---xrw-r-- 1 root bin  302108 11-13 06:03 log2012.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;将 log2012.log 文件由 root 群组该为 bin 群组</p>
<h3 id="实例2：根据指定未见改变文件的群组属性"><a href="#实例2：根据指定未见改变文件的群组属性" class="headerlink" title="实例2：根据指定未见改变文件的群组属性"></a>实例2：根据指定未见改变文件的群组属性</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chgrp --reference=log2012.log log2013.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">---xrw-r-- 1 root bin  302108 11-13 06:03 log2012.log</div><div class="line">-rw-r--r-- 1 root root     61 11-13 06:03 log2013.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#  chgrp --reference=log2012.log log2013.log </span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">---xrw-r-- 1 root bin  302108 11-13 06:03 log2012.log</div><div class="line">-rw-r--r-- 1 root bin      61 11-13 06:03 log2013.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;改变文件 log2013.log 的群组属性，是的文件 log2013.log 的群组属性和参考文件 log2012.log 的群组属性相同</p>
<h3 id="实例3-改变指定目录以及其子目录下的所有文件的群组属性"><a href="#实例3-改变指定目录以及其子目录下的所有文件的群组属性" class="headerlink" title="实例3.改变指定目录以及其子目录下的所有文件的群组属性"></a>实例3.改变指定目录以及其子目录下的所有文件的群组属性</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chgrp -R bin test6</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">drwxr-xr-x 2 root root   4096 11-30 08:39 test6</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test6</span></div><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">---xr--r-- 1 root root 302108 11-30 08:39 linklog.log</div><div class="line">---xr--r-- 1 root root 302108 11-30 08:39 log2012.log</div><div class="line">-rw-r--r-- 1 root root     61 11-30 08:39 log2013.log</div><div class="line">-rw-r--r-- 1 root root      0 11-30 08:39 log2014.log</div><div class="line">-rw-r--r-- 1 root root      0 11-30 08:39 log2015.log</div><div class="line">-rw-r--r-- 1 root root      0 11-30 08:39 log2016.log</div><div class="line">-rw-r--r-- 1 root root      0 11-30 08:39 log2017.log</div><div class="line">[root@localhost test6]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># chgrp -R bin test6</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test6</span></div><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">---xr--r-- 1 root bin 302108 11-30 08:39 linklog.log</div><div class="line">---xr--r-- 1 root bin 302108 11-30 08:39 log2012.log</div><div class="line">-rw-r--r-- 1 root bin     61 11-30 08:39 log2013.log</div><div class="line">-rw-r--r-- 1 root bin      0 11-30 08:39 log2014.log</div><div class="line">-rw-r--r-- 1 root bin      0 11-30 08:39 log2015.log</div><div class="line">-rw-r--r-- 1 root bin      0 11-30 08:39 log2016.log</div><div class="line">-rw-r--r-- 1 root bin      0 11-30 08:39 log2017.log</div><div class="line">[root@localhost test6]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">drwxr-xr-x 2 root bin    4096 11-30 08:39 test6</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;改变指定目录以及其子目录下的所有文件的群组属性</p>
<h3 id="实例4-通过群组织识别码改变文件群组属性"><a href="#实例4-通过群组织识别码改变文件群组属性" class="headerlink" title="实例4.通过群组织识别码改变文件群组属性"></a>实例4.通过群组织识别码改变文件群组属性</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">chgrp -R 100 test6</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># chgrp -R 100 test6</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">drwxr-xr-x 2 root users   4096 11-30 08:39 test6</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test6</span></div><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">---xr--r-- 1 root users 302108 11-30 08:39 linklog.log</div><div class="line">---xr--r-- 1 root users 302108 11-30 08:39 log2012.log</div><div class="line">-rw-r--r-- 1 root users     61 11-30 08:39 log2013.log</div><div class="line">-rw-r--r-- 1 root users      0 11-30 08:39 log2014.log</div><div class="line">-rw-r--r-- 1 root users      0 11-30 08:39 log2015.log</div><div class="line">-rw-r--r-- 1 root users      0 11-30 08:39 log2016.log</div><div class="line">-rw-r--r-- 1 root users      0 11-30 08:39 log2017.log</div><div class="line">[root@localhost test6]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;通过群识别码改变文件群组属性，100为 users 群组的识别码，具体群组和群组识别码可以去 /etc/group 文件中查看</p>

	

	
		<span class="different-posts"><a href="/2017/10/12/2. Linux 命令/29. Linux 命令- chgrp/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
